﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace XmlDSigEx
{
    class EnvelopedSignatureTransform:XPathFilter2Transform
    {
        internal const string URI_ENVELOPED_SIGNATURE_TRANSFORM = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";

        internal EnvelopedSignatureTransform(XmlDocument documentContext):base(documentContext)
        {
            XPathFilter2Expression expression = AddExpression(FilterType.Subtract, "here()/ancestor::ds:Signature[1]");
            expression.AddNamespace("ds", XmlSigner.NS_XMLDSIG);
        }       

        public override object Process(object input, XmlElement transformElement)
        {
            List<XmlNode> list = new List<XmlNode>(input as List<XmlNode>);
            XPathNavigator context = transformElement.CreateNavigator();
            return new List<XmlNode>(list.Intersect(base.ProcessXPathElement(context,  new List<XmlNode>(list), list, base.ExpressionList[0])));    
        }

        public override string Uri { get { return URI_ENVELOPED_SIGNATURE_TRANSFORM; } }

        public override void WriteXml(XmlWriter wrtier) { }

    
    }
}
